//
//  JSLTextView.m
//  
//
//  Created by 极速现金侠 on 2017/8/8.
//  Copyright © 2017年 innext. All rights reserved.
//

#import "JSLTextView.h"
#import <objc/runtime.h>
#import <objc/message.h>
@implementation JSLTextView

- (instancetype)init
{
    self = [super init];
    if (self) {
//        // 通过运行时，发现UITextView有一个叫做“_placeHolderLabel”的私有变量
//        unsigned int count = 0;
//        Ivar *ivars = class_copyIvarList([UITextView class], &count);
//        
//        for (int i = 0; i < count; i++) {
//            Ivar ivar = ivars[i];
//            const char *name = ivar_getName(ivar);
//            NSString *objcName = [NSString stringWithUTF8String:name];
//            NSLog(@"%d : %@",i,objcName);
//        }
//        // _placeholderLabel
        UILabel *placeHolderLabel = [[UILabel alloc] init];
        placeHolderLabel.text = @"请输入内容";
        placeHolderLabel.numberOfLines = 0;
        placeHolderLabel.textColor = [UIColor lightGrayColor];
        
        [placeHolderLabel sizeToFit];
        [self addSubview:placeHolderLabel];
        
        [self setValue:placeHolderLabel forKey:@"_placeholderLabel"];
        self.placeHolderLabel = placeHolderLabel;
        

    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
//    self.placeHolderLabel.top = 0;
//    self.placeHolderLabel.bottom = self.bottom;
//    self.placeHolderLabel.width = self.width;
}

- (void)setPlaceholder:(NSString *)placeholder{
    _placeholder = placeholder;
    self.placeHolderLabel.text = placeholder;
}

- (void)setPlaceholderColor:(UIColor *)placeholderColor{
    _placeholderColor = placeholderColor;
    self.placeHolderLabel.textColor = placeholderColor;
}

- (void)setPlaceholderFont:(UIFont *)placeholderFont{
    _placeholderFont = placeholderFont;
    self.placeHolderLabel.font = placeholderFont;
}

@end
